﻿#!/usr/bin/perl -w

use strict;  
use warnings;
use Net::FTP;


my $year = $ARGV[0];
my $month = $ARGV[1];
my $day = $ARGV[2];

print "---$year-$month-$day---\n";

# my $myHost = '10.91.17.170'; #clab822
my $myHost = '10.91.21.193'; #clab884
my $username = 'omc';  
my $password = 'omc';  
# my $remoteDir = "/var/opt/oss/global/mediation/south/pm/import/com.nsn.oss.nwi3/";  
my $remoteDir = "/var/opt/nokia/oss/osscore2/iscirp/pmupld_osscore2/";  
my $localDir = "./Output/OMeSFiles_";
$localDir .= $year.$month.$day."/";

opendir (DIR, $localDir) or die "can't open it:$!"; 
my @filelist = readdir DIR;
closedir(DIR); 
  
my $ftp = Net::FTP->new($myHost,Timeout => 30) or die "Can't connect: $@\n";  
$ftp->login($username, $password) or die "Could not log in.\n";  
if ($ftp->cwd($remoteDir)) {
	print "I'm in the directory ", $ftp->pwd(), "\n"; 
	
	while(my @dir_files = $ftp->ls($remoteDir."*.xml")){
	
		foreach my $file (@dir_files) {
			print "--There are files:$file\n";	
		}
		
		print "sleep 5s\n";
		sleep(5);
	}
	
	foreach my $file (@filelist) {
		next unless($file =~ /\.xml/);
		$file = $localDir.$file;
		print "--FTP put file:$file\n";
		my $result = $ftp->put($file);
	}		
}
 